package com.yc.cloud.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;

import static com.yc.cloud.common.constant.BaseConstant.*;

/**
 * 用户密码工具
 *
 * @author 杨智杰
 * @date 2021/7/20 9:33
 */
public class PasswordUtil {

    /**
     * 获得盐加密后的密码
     *
     * @param sale      加密盐,长度4
     * @param plaintext 明文,长度32
     * @return
     */
    public static String getPassWord(String sale, String plaintext) {
        if (StrUtil.isBlank(sale) || FOUR != sale.length()) {
            return null;
        }
        if (StrUtil.isBlank(plaintext) || THIRTY_TWO != plaintext.length()) {
            return null;
        }
        return SecureUtil.md5(plaintext.substring(ZERO, EIGHT) + sale.substring(ZERO, ONE)
                + plaintext.substring(EIGHT, SIXTEEN) + sale.substring(ONE, TWO)
                + plaintext.substring(SIXTEEN, TWENTY_FOUR) + sale.substring(TWO, THREE)
                + plaintext.substring(TWENTY_FOUR, THIRTY_TWO) + sale.substring(THREE, FOUR));
    }

}
